package com.echo.code.thread.atomic;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * AtomicIntegerExam Created by baiyap on 2018/10/10.
 */
public class AtomicIntegerExam {

  public static void main(String[] args) throws InterruptedException {
    AtomicInteger atomicInteger = new AtomicInteger(0);
    ExecutorService service = Executors.newCachedThreadPool();
    for (int j = 0; j < 10; j++) {
      service.execute(() -> {
        for (int k = 0; k < 10000; k++) {
          atomicInteger.incrementAndGet();
        }
      });
    }
    service.shutdown();
    service.awaitTermination(1, TimeUnit.DAYS);
    System.out.println(atomicInteger.get());
  }
}
